<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "ticket_sales".
 *
 * @property int $id
 * @property int $event_id
 * @property string|null $date_sale
 * @property int|null $is_cancell
 * @property int|null $is_refund
 * @property float|null $tariff
 * @property string|null $selling_platform
 * @property string|null $payment_method
 *
 * @property Event $event
 */
class TicketSales extends \yii\db\ActiveRecord
{
    const ONLINE_SALE = 1;
    const OFFLINE_SALE = 0;
    
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'ticket_sales';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['event_id', 'ticket_number'], 'required'],
            [['event_id', 'is_cancell', 'is_refund', 'is_online_sale'], 'integer'],
            [['date_sale'], 'safe'],
            [['tariff'], 'number'],
            [['selling_platform', 'payment_method', 'ticket_number'], 'string', 'max' => 255],
            [['event_id'], 'exist', 'skipOnError' => true, 'targetClass' => Event::className(), 'targetAttribute' => ['event_id' => 'id']],
            [['ticket_number'], 'unique'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'event_id' => 'Event ID',
            'date_sale' => 'Date Sale',
            'is_cancell' => 'Is Cancell',
            'is_refund' => 'Is Refund',
            'tariff' => 'Tariff',
            'selling_platform' => 'Selling Platform',
            'payment_method' => 'Payment Method',
            'ticket_number' => 'Номер билета',
        ];
    }

    /**
     * Gets query for [[Event]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getEvent()
    {
        return $this->hasOne(Event::className(), ['id' => 'event_id']);
    }
}
